package CDIO2;

import java.io.File;
import java.io.IOException;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;


public class Field {
	private int number;

	private String name;
	private int points;
	private String messege;
	
	public Field(int index){
		_init(index);
	}
	
	private void _init(int index){
		SAXBuilder builder = new SAXBuilder();
		number=index;
		
		
			Document doc;
			try {
				doc = builder.build(new File("./src/xml/fields.xml"));
				Element root = doc.getRootElement();
				
			
			for(Element elemt : root.getChildren("field")){
				
				if(Integer.parseInt(elemt.getAttributeValue("number"))==number){
										
					name = elemt.getChildText("name");
					points = Integer.parseInt(elemt.getChildText("points"));
					messege = elemt.getChildText("messege");
				}
			}
			
			
			} catch (JDOMException | IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
		
	}
	
	public String getName(){
		return name;
	}
	public String getMessege(){
		return messege;
	}
	public int getPoint(){
		return points;
	}
	public int getNumber(){
		return number;
	}
	
	public String toString(){
		return ""+messege + "\n" + number + points;
	}
	
}
